package controllers

import (
	"gitee.com/cjf8134/bbs_serve/internal/app/apiserve/services"
	"gitee.com/cjf8134/bbs_serve/internal/pkg/requests"
	"gitee.com/cjf8134/bbs_serve/internal/pkg/utils/responseutil"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type CategoryController struct {
	logger  *zap.Logger
	service services.DefaultService
}

func NewCategoryController(logger *zap.Logger, s services.DefaultService) *CategoryController {
	return &CategoryController{
		logger:  logger.With(zap.String("type", "CategoryController")),
		service: s,
	}
}

// Category list  分类列表
func (pc *CategoryController) List(c *gin.Context) {
	var req requests.CategoryList
	if err := c.ShouldBindJSON(&req); err != nil {
		pc.logger.Error("request params error = ", zap.Error(err))
		responseutil.FailJson(c, "request params error")
		return
	}
	list, err := pc.service.CategoryList(&req)
	if err != nil {
		pc.logger.Error("error", zap.Error(err))
		responseutil.FailJson(c, err.Error())
		return
	}
	responseutil.SusJson(c, "success", list)
}
